@extends('layouts.admin')

@section('title', '编辑店铺')

@section('content')
    <div class="console-title">
        <div class="float-right">
            <a href="{{admin_url('shop')}}"><span class="btn btn-primary">返回列表</span></a>
        </div>
        <h2>店铺管理->编辑店铺</h2>
    </div>
    <div class="tabs-container">
        <ul class="tabs">
            <li role="presentation" class="tab-item">
                <a class="tab-link" :class="{active:tab=='basic'}" v-on:click="switchTab('basic')">基本信息</a>
            </li>
            <li role="presentation" class="tab-item">
                <a class="tab-link" :class="{active:tab=='auth'}" v-on:click="switchTab('auth')">认证信息</a>
            </li>
        </ul>
    </div>
    <div class="content-div">
        <form method="post" id="Form" autocomplete="off">
            {{form_verify_field()}}
            <div v-show="tab=='basic'">
                <table cellspacing="0" cellpadding="0" width="100%" class="formtable">
                    <tbody>
                    <tr>
                        <td class="cell-name" width="80">店铺名称</td>
                        <td><input title="" type="text" name="shop[shop_name]" value="{{$shop['shop_name']}}" id="shop_name" class="form-control w300"></td>
                    </tr>
                    <tr>
                        <td class="cell-name">客服电话</td>
                        <td><input title="" type="text" name="shop[phone]" value="{{$shop['phone']}}" id="phone" class="form-control w300"></td>
                    </tr>
                    <tr>
                        <td class="cell-name">店铺标志</td>
                        <td>
                            <input type="hidden" name="shop[logo]" value="{{$shop['logo']}}" id="logo">
                            <img src="{{image_url($shop['logo'])}}" width="100" height="100" id="logo_img">
                        </td>
                    </tr>
                    <tr>
                        <td class="cell-name">店铺简介</td>
                        <td>
                            <textarea class="form-control" name="shop[description]" style="width: 300px; height: 80px;" placeholder="【掌柜签名】/【店铺动态】/【主营宝贝】">{{$shop['description']}}</textarea>
                        </td>
                    </tr>
                    <tr>
                        <td class="cell-name">经营地址</td>
                        <td>
                            <label>
                                <select title="" class="form-control width-auto" name="shop[province]" id="province">
                                    <option value="">请选择</option>
                                </select>
                            </label>
                            <label>
                                <select title="" class="form-control width-auto" name="shop[city]" id="city" style="width: auto;">
                                    <option value="">请选择</option>
                                </select>
                            </label>
                            <label>
                                <select title="" class="form-control width-auto" name="shop[district]" id="district" style="width: auto;">
                                    <option value="">请选择</option>
                                </select>
                            </label>
                        </td>
                    </tr>
                    <tr>
                        <td class="cell-name">街道地址</td>
                        <td>
                            <label>
                                <input type="text" name="shop[street]" id="street" class="form-control w300" value="{{$shop['street']}}" placeholder="街道地址">
                            </label>
                            <label>
                                <a id="showMapLocation" style="color: #0B90EF;">地图定位</a>
                                <input type="hidden" name="shop[lat]" id="lat" value="{{$shop['lat']}}">
                                <input type="hidden" name="shop[lng]" id="lng" value="{{$shop['lng']}}">
                            </label>
                        </td>
                    </tr>
                    <tr>
                        <td class="cell-name">主要货源</td>
                        <td>
                            <label><input type="radio" name="shop[main_source]" value="1"@if($shop['main_source'] == 1) checked="checked"@endif> 自己生产</label>
                            <label><input type="radio" name="shop[main_source]" value="2"@if($shop['main_source'] == 2) checked="checked"@endif> 代工生产</label>
                            <label><input type="radio" name="shop[main_source]" value="3"@if($shop['main_source'] == 3) checked="checked"@endif> 线下批发</label>
                            <label><input type="radio" name="shop[main_source]" value="4"@if($shop['main_source'] == 4) checked="checked"@endif> 分销代销</label>
                            <label><input type="radio" name="shop[main_source]" value="5"@if($shop['main_source'] == 5) checked="checked"@endif> 自由渠道</label>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div v-show="tab=='auth'">
                <table cellspacing="0" cellpadding="0" width="100%" class="formtable">
                    <tbody>
                    <tr>
                        <td class="cell-name" width="80">店主姓名</td>
                        <td><input title="" type="text" name="auth[shop_owner]" value="{{$auth['shop_owner']}}" id="shop_owner" class="form-control w300"></td>
                    </tr>
                    <tr>
                        <td class="cell-name">身份证号</td>
                        <td><input title="" type="text" name="auth[id_card_no]" value="{{$auth['id_card_no']}}" id="id_card_no" class="form-control w300"></td>
                    </tr>
                    <tr>
                        <td class="cell-name">身份证照正面</td>
                        <td>
                            <input type="hidden" name="auth[id_card_pic_1]" value="{{$shop['id_card_pic_1']}}" id="id_card_pic_1">
                            <img src="{{image_url($auth['id_card_pic_1'])}}" width="100" height="100" id="id_card_img_1">
                        </td>
                    </tr>
                    <tr>
                        <td class="cell-name">身份证照反面</td>
                        <td>
                            <input type="hidden" name="auth[id_card_pic_2]" value="{{$shop['id_card_pic_2']}}" id="id_card_pic_2">
                            <img src="{{image_url($auth['id_card_pic_2'])}}" width="100" height="100" id="id_card_img_2">
                        </td>
                    </tr>
                    <tr>
                        <td class="cell-name">手持身份证照</td>
                        <td>
                            <input type="hidden" name="auth[id_card_pic_3]" value="{{$shop['id_card_pic_3']}}" id="id_card_pic_3">
                            <img src="{{image_url($auth['id_card_pic_3'])}}" width="100" height="100" id="id_card_img_3">
                        </td>
                    </tr>
                    <tr>
                        <td class="cell-name">营业执照编号</td>
                        <td>
                            <input title="" type="text" name="auth[license_no]" value="{{$auth['license_no']}}" class="form-control w300">
                        </td>
                    </tr>
                    <tr>
                        <td class="cell-name">营业执照照片</td>
                        <td>
                            <input type="hidden" name="auth[license_pic]" value="{{$shop['license_pic']}}" id="license_pic">
                            <img src="{{image_url($auth['license_pic'])}}" width="100" height="100" id="license_img">
                        </td>
                    </tr>
                    <tr>
                        <td class="cell-name">其他证件照</td>
                        <td>
                            <input type="hidden" name="auth[other_pic]" value="{{$shop['other_pic']}}" id="other_pic">
                            <img src="{{image_url($auth['other_pic'])}}" width="100" height="100" id="other_img">
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <table cellspacing="0" cellpadding="0" width="100%" class="formtable">
                <tfoot>
                <tr>
                    <td width="80"></td>
                    <td colspan="2">
                        <button type="button" class="btn btn-primary w100" id="submitButton">提交</button>
                    </td>
                </tr>
                </tfoot>
            </table>
        </form>
    </div>
@stop

@section('foot')
    <script type="text/javascript">
        function init() {
            var district = new DistrictSelector({
                province:'{{$shop['province']}}',
                city:'{{$shop['city']}}',
                district:'{{$shop['district']}}'
            });

            $("#logo_img").on('click', function () {
                Plugins.showImagePicker(function (data) {
                    $("#logo").val(data.image);
                    $("#logo_img").attr('src', data.imageurl);
                });
            });

            $("#id_card_img_1").on('click', function () {
                Plugins.showImagePicker(function (data) {
                    $("#id_card_pic_1").val(data.image);
                    $("#id_card_img_1").attr('src', data.imageurl);
                });
            });

            $("#id_card_img_2").on('click', function () {
                Plugins.showImagePicker(function (data) {
                    $("#id_card_pic_2").val(data.image);
                    $("#id_card_img_2").attr('src', data.imageurl);
                });
            });

            $("#id_card_img_3").on('click', function () {
                Plugins.showImagePicker(function (data) {
                    $("#id_card_pic_3").val(data.image);
                    $("#id_card_img_3").attr('src', data.imageurl);
                });
            });

            $("#license_img").on('click', function () {
                Plugins.showImagePicker(function (data) {
                    $("#license_pic").val(data.image);
                    $("#license_img").attr('src', data.imageurl);
                });
            });

            $("#other_img").on('click', function () {
                Plugins.showImagePicker(function (data) {
                    $("#other_pic").val(data.image);
                    $("#other_img").attr('src', data.imageurl);
                });
            });

            $("#submitButton").on('click', function () {
                var shop_name = $.trim($("#shop_name").val());
                if (!shop_name) {
                    DSXUI.showToast('请输入店铺名称');
                    return false;
                }
                var phone = $.trim($("#phone").val());
                if (!phone){
                    DSXUI.showToast('请输入客服电话');
                    return false;
                }

                $("#Form").submit();
            });

            $("#showMapLocation").on('click', function () {
                Plugins.showMapView({}, function (position) {
                    $("#lat").val(position.lat);
                    $("#lng").val(position.lng);
                });
            });
        }

        var app = new Vue({
            el:'#app',
            data:{
                tab:'basic'
            },
            mounted:function(){
                init();
            },
            methods:{
                switchTab:function (tab) {
                    this.tab = tab;
                }
            }
        });
    </script>
@stop
